local skynet        = require "skynet"
local bewater       = require "bw.bewater"
local id_producer   = require "bw.server.id_producer"
local mongo         = require "db.mongo"
local sname         = require "sname"

function id_producer.shutdown()
    id_producer.save()
end

bewater.start(id_producer, function()
    skynet.call(sname.MONITOR, "lua", "register", skynet.self())
    id_producer.start({
        load_id = function()
            return mongo.get("autoid") or 1000000
        end,
        save_id = function(id)
            return mongo.set("autoid", id)
        end,
    })
end)
